<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>novalContent</title>
    <link rel="stylesheet" href="../statics/css/bootstrap.min copy.css">
    <link rel="stylesheet" href="../statics/css/novalContent.css">
</head>

<body background="../statics/Photo/雪地.jpg" style="background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
width:100%;">
    <div class="container">
        <div class="row">
            <div class="col-sm">
                <div id="left">
                    <div id="personalData">
                        <div class="card-header"
                            style="font-family: fantasy; font-size: 25px;margin-left: 28px; float: left;margin-bottom: 5px;border: solid 2px black;border-radius: 8px;">
                            Personal Data
                        </div>
                        <p style="font-family: fantasy;"></p>

                        <!-- 头像 -->
                        <img src="../statics/Photo/p.png" alt="" style="margin-left: 20px;margin-top: 0px;">
                        <p></p>
                        <!-- 昵称 -->
                        <p
                            style="font-family: fantasy;font-size: 20px;margin-left: 40px;border: solid 2px black;border-radius: 8px;width: 160px;text-align: center;color: #000;">
                            User:&nbsp;&nbsp;&nbsp;&nbsp;{{username}}</p>
                        <!-- 虚线 -->
                        <hr style="border:1px dashed #000" />

                        <p></p>
                        <li id="friends" style="border: solid 2px black;border-radius: 5px;display: inline;">加好友</li>
                        <li id="addNews" style="border: solid 2px black;border-radius: 5px;display: inline;">加关注</li>
                        <p></p>
                        <li id="sendPaper" style="border: solid 2px black;border-radius: 5px;display: inline;">发纸条</li>
                        <li id="writeTalk" style="border: solid 2px black;border-radius: 5px;display: inline;">写留言</li>
                        <p></p>

                        <hr style="border:1px dashed #000" />

                        &nbsp;&nbsp;<span
                            style="font-family:fantasy;">Level:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span style="font-family: fantasy;font-size: larger ;">130</span><br>
                        <br>

                        &nbsp;&nbsp;&nbsp;<span style="font-family:fantasy;">P&nbsp;&nbsp;V:</span>
                        <span
                            style="font-family: fantasy;font-size: larger ;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4,546,231,742</span><br>
                        <br>

                        &nbsp;<span style="font-family:fantasy;">Attention:</span>
                        <span style="font-family: fantasy;font-size: larger ;">&nbsp;&nbsp;&nbsp;945,213</span><br>
                        <br>

                        &nbsp;<span style="font-family:fantasy;">Gold Icon:</span>
                        <span style="font-family:fantasy;">&nbsp;&nbsp;&nbsp;&nbsp;133,785</span><br>
                        <br>

                        &nbsp;&nbsp;<span style="font-family:fantasy;">Medal:</span>
                        <span style="font-family:fantasy;">&nbsp;&nbsp;&nbsp;&nbsp;</span>

                    </div>
                </div>
            </div>


            <div class="col-sm">
                <div class="card-header"
                    style="font-family: fantasy; font-size: 25px;;border: solid 2px black;border-radius: 8px;height: 60px;margin-top: 20px;">
                    Just Saying
                </div>
                <div style="width: 52rem;opacity: 0.7;">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-4 d-flex justify-content-start">
                                <button type="button" class="btn btn-secondary btn-sm" data-toggle="modal"
                                    data-target="#saysomething"
                                    style="font-family: fantasy;font-size: 20px;background-color:deepskyblue;">Post</button>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-center">
                                <p style="font-family: fantasy;font-size: 14px;margin-top: 10px;">Welcome to your
                                    write life📕</p>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-end"><button type="button"
                                    class="btn btn-secondary btn-sm" onclick="logout()"
                                    style="font-family: fantasy;font-size: 20px;background-color:deepskyblue;">Logout</button>
                            </div>
                        </div>
                    </div>

                </div>
                <div id="Content" style="height: 400px;width: 500px;">
                    <div class="row" style="margin-top:5px;opacity: 0.7;">
                        <div class="col-sm">
                        </div>
                        <div class="col-sm" id="saysayMsg" style="width: 50rem;">
                            {% for msg in msgs %}
                            <div class="card border-primary shadow"
                                style="height: 520px;position: relative;overflow: auto;">
                                <div class="card-header">
                                    <div class="row">
                                        <div class="col-sm-10">{{msg.content}}</div>
                                        <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                                data-toggle="modal" data-target="#comment"
                                                onclick="msgCommit('{{msg.id}}')">Talk Show</button>
                                        </div>
                                    </div>

                                </div>
                                <div class="card-body">
                                    <ul class="list-group list-group-flush" id="{{msg.id}}">
                                        {% for cmot in msg.comments %}
                                        <li class="list-group-item">
                                            <blockquote class="blockquote mb-0">
                                                <p>{{cmot.content}}</p>
                                                <footer class="blockquote-footer">
                                                    <cite title="Source Title">{{cmot.comUserName}}</cite>&nbsp;&nbsp;对
                                                    <cite title="Source Title">{{msg.msgUserName}}</cite>&nbsp;&nbsp;说
                                                </footer>
                                            </blockquote>
                                        </li>
                                        {% endfor %}
                                    </ul>

                                </div>
                            </div>

                            {% endfor %}

                        </div>
                        <div class="col-sm">
                        </div>
                    </div>

                </div>
            </div>
            <div class="col-sm">
            </div>

        </div>


    </div>

    <div class="modal fade" id="saysomething" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">post talk</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline" name="msgSay"
                                id="msgSay">
                            </small>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">CANCLE</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="say()">POST</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="comment" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Talk Show</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline"
                                id="commentText">
                            <!-- <small id="passwordHelpInline" class="text-muted">
                            Must be 8-20 characters long.
                          </small> -->
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancle</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="talkComment()">Talk
                        Show</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="../statics/js/jquery-3.6.0.min.js"></script>
<script src="../statics/js/bootstrap.min.js"></script>

<script>
    let currentMsgId = '';
    function logout() {
        $.ajax({
            url: "/logout",
            type: "POST",
            dataType: "json",
            success: function (res) {
                if (res.code === 200) {
                    window.location.href = '/login'
                }
            },
            error: function (msg) {
                console.log('网络错误！');
            }
        })
    }

    function say() {
        var getTime = new Date();
        var YY = getTime.getFullYear();
        var MM = getTime.getMonth() + 1;
        var DD = getTime.getDate();
        var hh = getTime.getHours();
        var mm = getTime.getMinutes();
        var ss = getTime.getSeconds();
        var day = getTime.getDay();
        let data = {
            msgSay: $('#msgSay').val()
        }
        $.ajax({
            url: "/say",
            type: "POST",
            dataType: "json",
            data: data,
            success: function (res) {
                console.log(res);
                if (res.code === 200) {
                    let data = JSON.parse(res.data);
                    console.log(data);
                    var time = "发表时间：" + YY + "年" + MM + "月" + DD + "号" + hh + "时" + mm + "分" + ss + "秒";
                    let html = time + `
                        <div class="card border-primary shadow" style="width: 50rem;">
                            <div class="card-header">
                                <div class="row">
                                    <div class="col-sm-10">${data.content}</div>
                                    <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                            data-toggle="modal" data-target="#comment"
                                            onclick="msgCommit(${data.id})" style="background-color:deepskyblue">Talk Show</button>
                                    </div>
                                </div>

                            </div>
                            <div class="card-body">
                                <ul class="list-group list-group-flush" id="${data.id}">
                                   
                                </ul>

                            </div>
                        </div>
                        `;
                    $("#saysayMsg").prepend(html);
                    // window.location.href="/login";
                }
            },
            error: function (msg) {
                console.log('网络或者服务器有问题');
            }
        })
    }
    function msgCommit(msgId) {
        currentMsgId = msgId;
    }
    function talkComment() {
        var getTime = new Date();
        var YY = getTime.getFullYear();
        var MM = getTime.getMonth() + 1;
        var DD = getTime.getDate();
        var hh = getTime.getHours();
        var mm = getTime.getMinutes();
        var ss = getTime.getSeconds();
        var day = getTime.getDay();

        let data = {
            msgId: currentMsgId,
            content: $('#commentText').val()
        }
        $.ajax({
            url: "/comment",
            type: "POST",
            dataType: "json",
            data: data,
            success: function (res) {
                console.log(res);
                if (res.code === 200) {
                    var time = "吐槽时间：" + YY + "年" + MM + "月" + DD + "号" + hh + "时" + mm + "分" + ss + "秒";
                    let html = `
                            <li class="list-group-item">
                                <blockquote class="blockquote mb-0">
                                    <p>${data.content}</p>
                                    <footer class="blockquote-footer">
                                        <cite title="Source Title">${data.fromUserName}</cite>&nbsp;&nbsp;对
                                        <cite title="Source Title">${data.toUserName}</cite>&nbsp;&nbsp;说
                                    </footer>
                                </blockquote>
                            </li>
                        `+ time;
                    $("#" + currentMsgId).append(html);
                }
            },
            error: function (msg) {
                console.log('网络或者服务器有问题');
            }
        });
    }



</script>



</html>